import React, { useEffect, useState, useRef } from 'react';
import TableDataBlock from '@/components/TableDataBlock';
import PopImgShow from '@/components/PopImgShow';
import { connect } from 'umi';
import { Space } from 'antd'
import { order_status, goodsType_status, workType_status,  } from '@/common/contact';
const UserScore = (props) => {
  const { dispatch, loading, list, hideFlag: showHide } = props;
  const { id } = props
  const hideFetch = (hideFlag, o) => {
    dispatch({
      type: 'weCom/fakeSetThirdEventHideFlag',
      payload: {
        hideFlag: hideFlag,
        id: o
      },
      callback: (e, total) => {
        handleCallback()
      },
    });
  }
  const handleCallback = () => {
    childRef.current.fetchGetData();
  };
  const searchItems = [
    {
      label: '创建时间',
      type: 'rangePicker',
      name: 'startDate',
      end: 'endDate',
    },
  ];
  const getColumns = [
    {
      title: "事件名称",
      dataIndex: 'eventName',
    },

    {
      title: '事件Key',
      dataIndex: 'eventKey',
    },
    {
      title: '事件描述',
      dataIndex: 'scoreDesc',
    },
    {
      title: '发起时间',
      dataIndex: 'createTime',
    },
    {
      title: '员工姓名',
      dataIndex: 'adminName',
    },
    {
      type: 'handle',
      show: showHide !== '0',
      width: 200,
      dataIndex: 'id',
      render: (val, record) => [
        {
          title: '显示',
          visible: record.hideFlag === '1' && showHide !== '0',
          click: () => {
            const { hideFlag, id } = record
            hideFetch('0', id)
          },
        },
        {
          title: '隐藏',
          visible: record.hideFlag !== '1' && showHide !== '0',
          click: () => {
            const { hideFlag, id } = record
            hideFetch('1', id)
          },
        },
      ],
    },
  ].filter(val => {
    const { show = true } = val
    return show
  });
  const childRef = useRef();
  return (
    <TableDataBlock
      params={{ organizationUserId: id, hideFlag: showHide }}
      cRef={childRef}
      searchItems={searchItems}
      loading={loading}
      columns={getColumns}
      rowKey={(record) => `${record.id}`}
      dispatchType="user/fetchListUserThirdThirdEvent"
      {...list}
    ></TableDataBlock>
  );
};
export default connect(({ user, loading }) => ({
  list: user.eventInfoList,
  loading: loading.effects['user/fetchListUserThirdThirdEvent'],
}))(UserScore);;
